
const webpack = require('webpack')
const merge = require('webpack-merge');
const base = require('./webpack.base');
const CompressionWebpackPlugin = require("compression-webpack-plugin")

const prodConfig = {
  devtool: 'cheap-module-source-map',
  optimization: {
    minimize: true,
    runtimeChunk: {
        name: "manifest"
    },
    splitChunks: {
        cacheGroups: {
            vendor: {
                test: /[\\/]node_modules[\\/]/,
                name: "vendors",
                priority: -20,
                chunks: "all"
            }
        }
    }
  },
  plugins: [
    new CompressionWebpackPlugin({
      filename: '[path].gz[query]', // 压缩后的文件名
      algorithm: 'gzip', // 算法 默认gzip
      test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'), // 针对文件的正则表达式规则，符合规则的文件被压缩
      threshold: 10240, // 文件大于这个值的会被压缩
      minRatio: 0.8 // 压缩率 默认0.8
    })
  ]
}

module.exports = merge(base, prodConfig)